Repository navigation
Write push buttons that share a name as one field with each widget as a kid - #447
Merged
jakejackson1 merged 3 commits intoSep 23, 2026
Merged
Conversation
… a kid Same-named submit, reset, script and image buttons were written as separate fields with the same /T, and their script and icon were looked up by name, so the second button's script replaced the first's and was then used up. Each group is now a parent field (/FT /Btn, push-button flag, /T, /Kids) listed in /AcroForm /Fields but in no page's /Annots, and its widgets keep their own action, caption, icon and appearance under a /Parent. Scripts and icons are keyed by the button's form number. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…per, and write the push-button flag as the widgets do Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1
added a commit
that referenced
this pull request
Sep 23, 2026
… a kid (#447) * Write push buttons that share a name as one field with each widget as a kid Same-named submit, reset, script and image buttons were written as separate fields with the same /T, and their script and icon were looked up by name, so the second button's script replaced the first's and was then used up. Each group is now a parent field (/FT /Btn, push-button flag, /T, /Kids) listed in /AcroForm /Fields but in no page's /Annots, and its widgets keep their own action, caption, icon and appearance under a /Parent. Scripts and icons are keyed by the button's form number. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Read the reference lists in the shared button name tests with one helper, and write the push-button flag as the widgets do Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Say what a push button is where the shared button name code asks Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1
added a commit
that referenced
this pull request
Sep 23, 2026
#441 moved SetJSButton()'s SetFormButton() call below the icon, so that the field knows it shows one, and #447 keyed the icon by $this->formCount, which is the button's number only once SetFormButton() has counted it. Merged together, each icon went to the form before it: the widget lost its icon, the object count reserved one that was never written, and SetFormButton() still looked the icon up by name. The icon is now kept under the number the button is about to get, and SetFormButton() looks for it there. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1
added a commit
that referenced
this pull request
Sep 23, 2026
… a kid (#447) * Write push buttons that share a name as one field with each widget as a kid Same-named submit, reset, script and image buttons were written as separate fields with the same /T, and their script and icon were looked up by name, so the second button's script replaced the first's and was then used up. Each group is now a parent field (/FT /Btn, push-button flag, /T, /Kids) listed in /AcroForm /Fields but in no page's /Annots, and its widgets keep their own action, caption, icon and appearance under a /Parent. Scripts and icons are keyed by the button's form number. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Read the reference lists in the shared button name tests with one helper, and write the push-button flag as the widgets do Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Say what a push button is where the shared button name code asks Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1
added a commit
that referenced
this pull request
Sep 23, 2026
#441 moved SetJSButton()'s SetFormButton() call below the icon, so that the field knows it shows one, and #447 keyed the icon by $this->formCount, which is the button's number only once SetFormButton() has counted it. Merged together, each icon went to the form before it: the widget lost its icon, the object count reserved one that was never written, and SetFormButton() still looked the icon up by name. The icon is now kept under the number the button is about to get, and SetFormButton() looks for it there. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #443
Push buttons that share a
nameare now written as one field, with each widget as a kid. Before, the second button's script replaced the first's, and then the second button had no action at all.What changed
One field per shared name. Submit, reset, script and image buttons that share a name are written as one parent field:
<< /FT /Btn /Ff 65536 /T (go) /Kids [ … ] >>. This is the shape ISO 32000-1 §12.7.3.2 requires for two widgets that share a fully qualified name./AcroForm /Fieldslists it, and no page's/Annotsdoes./Annots. It has a/Parentand no/T, and keeps its own/MKcaption and icon,/AAaction,/TUand/AP.Form::addButtonGroupIds()numbers the parents inMetadataWriter::numberAnnotations(), after the radio groups.Form::putButtonGroups()writes them after_putRadioItems().$formsat output time, not when each button is set. Only buttons that actually made it onto a page are counted: a block measured forpage-break-inside: avoidand then drawn again contributes each button once.Scripts and icons are keyed by the button, not its name.
array_form_button_jsandform_button_iconare now keyed by the button's form number ($form['n']), so a second button no longer overwrites the first's entry.unset()after the first widget uses it.SetFormButtonJS()now takes that number instead of a name. Its only caller isSetJSButton().Unchanged:
/T.SubmitorReset, so two of them are now gathered like any other shared name. Once Give a button with no name a name of its own #438 gives them distinct names, they stay separate fields.Snapshots
None changed.
BasicHtmlSnapshotTesthas four buttons namedsubmit, but it doesn't turn onuseActiveForms, so it draws static buttons. Theform-fields-*fixtures give every button a different name.Verification
tests/Mpdf/SharedButtonNameTest.php(7 tests; all fail without the fix except the import check):/T (go)and two kids, the kids have no/T, and each runs its own script;/T;/AAand no/JS;page-break-inside: avoidblock that moves to the next page are gathered once each;setSourceFile()/importPage().AnnotationObjectNumbersTestadds two buttons namedgoon page 1 and one on page 2, image buttons namedbon both pages, and a lone reset. It checks, under every setup (including PDF/A-2b), that:/Parentlists its kid;/T;/Fieldsand in no/Annots;/Sizeis written.PdfaConformanceTest::testActiveFormConformsgains a second button namedb. veraPDF passes the conformance group: 29 tests, across 1-B, 2-B, 2-U, 3-B and 3-U with sRGB and CMYK intents.pdftoppmand Ghostscript. All three captions draw.pdfinfo -jsshows each widget with its own script. pypdf finds the fieldsgoandlone.composer test: 3779 tests OK, the usual 5 skips.--group=snapshot: 89 OK.composer cs: clean.$js in isset()inForm.phpdrops from 2 to 1.php -lunder PHP 5.6: clean on every changed file.Upstream (create-upstream-pr)
The name-keyed JS and icon lookups and the duplicate
/Tare the same on mpdf/mpdfdevelopment, and the fix carries over. Two parts depend on this branch and need adapting there:numberAnnotations(), alongside the radio groups'obj_id. Upstream still predicts ids inPageWriter. There, the parents need numbering after the radio groups (radio_on_obj_id) and adding to the object count, and the kids'/Annotsentries stay as they are./AP << /N << /Push … >> >>and the PDF/A action dropping come from Give every active form widget its own appearance, and ask the viewer to redraw only text it cannot shape (#348, #59) #387. Upstream buttons have no/AP, so only the/Parent,/Tand keying changes apply.Limits
array_form_text_jsandarray_form_choice_jsand a duplicate/T. They need a decision of their own, as the issue says./Widgetannotation (existing code). The new button parent is a plain field.🤖 Generated with Claude Code